﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Ict.DataAccess.Linq
{
    /// <summary>
    /// 将源查询的结果转换为另一种类型的查询
    /// </summary>
    /// <typeparam name="T"></typeparam>
    class SelectableNew<T> : Selectable<T>
    {
        private SelectableBase sourceQuery;

        

        internal SelectableNew(SelectableBase sourceQuery, LambdaExpression selectClause)
        {
            ((ExecutableProvider)this.Provider).Executor = ((ExecutableProvider)sourceQuery.Provider).Executor;
            this.sourceQuery = sourceQuery;
            this.SelectClause = selectClause;
        }

        internal SelectableBase SourceQuery
        {
            get
            {
                return sourceQuery;
            }
        }

        internal override string MapField(MemberExpression memberAccess)
        {
            return sourceQuery.MapField(memberAccess);
        }

        internal override void BuildSql(StringBuilder stringBuilder)
        {
            sourceQuery.SelectClause = this.SelectClause;
            sourceQuery.TakeCount = this.TakeCount;
            sourceQuery.IsCountOnly = this.IsCountOnly;
            sourceQuery.BuildSql(stringBuilder);
        }

        internal override void BuildQueryList(StringBuilder stringBuilder)
        {
            sourceQuery.BuildQueryList(stringBuilder);
        }

        internal override void BuildCondition(StringBuilder stringBuilder)
        {
            sourceQuery.BuildCondition(stringBuilder);
        }
    }
}
